package com.neutech.controller;

import com.neutech.service.PdrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
public class PdrugController {
    @Autowired
    private PdrugService pdrugService;
    @RequestMapping("/querypdrug")
    @ResponseBody
    public List<Map<String ,Object>> queryPdrugByName(@RequestParam Map map){
        List<Map<String,Object>> list = pdrugService.queryPdrugByName(map.get("name").toString());
        System.out.println(list);
        return pdrugService.queryPdrugByName(map.get("name").toString());
    }
    @RequestMapping("/updatepdrug")
    @ResponseBody
    public void updatePdrugByName(){
        pdrugService.updatePdrugByName();
    }

    @RequestMapping("/addpdrug")
    @ResponseBody
    public void addPdrug(@RequestParam Map map){
        for(Object key:map.keySet()){
            String value = (String) map.get(key);
            System.out.println(key + ":" + value);
        }
        map.put("state","未发");
        pdrugService.addPdrug(map);
    }
    @RequestMapping("idpdrug")
    @ResponseBody
    public List<Map<String ,Object>> queryPdrugByIdnumber(@RequestParam Map map){
        //List<Map<String,Object>> list = pdrugService.queryPdrugByName(map.get("name").toString());
        //System.out.println(list);
        return pdrugService.queryPdrugByIdnumber(Integer.parseInt(map.get("idnumber").toString()));
    }
    @RequestMapping("notpdrug")
    @ResponseBody
    public List<Map<String ,Object>> queryNotPdrug(){

        return pdrugService.queryNotPdrugByState();
    }
    @RequestMapping("alpdrug")
    @ResponseBody
    public List<Map<String ,Object>> queryAlPdrug(){

        return pdrugService.queryAlPdrugByState();
    }
    @ResponseBody
    @RequestMapping("/uppdrug")
    public void register(@RequestParam Map map)
    {
        System.out.println(map.get("idnumber"));
        pdrugService.updatePdrugByIdnumber(Integer.parseInt(map.get("idnumber").toString()));
    }
    @ResponseBody
    @RequestMapping("/delpdrug")
    public void delpdrug(@RequestParam Map map)
    {
        pdrugService.delpdrug(Integer.parseInt(map.get("num").toString()));

    }

}
